home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…eptember: Technology Seed / September 98 ADC Seed CD.toast / Language Analysis Manager / DarumaDR1Package / Examples / LanguageAnalysisTestApp / Sources / Initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  7.2 KB  |  275 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Initialize.c
  3.  
  4.      Contains:    Sample code for Language Analysis Manager.
  5.  
  6.      Version:    Technology:    System 8
  7.                  Release:    Daruma Developer Release 1
  8.  
  9.      Copyright:    1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Contact:    daruma@apple.com
  12.  
  13. */
  14.  
  15.  
  16. #include "TestApp.h"
  17. #include "FunctionProto.h"
  18.  
  19. #include <Fonts.h>
  20. #include <Menus.h>
  21. #include <Resources.h>
  22. #include <TextUtils.h>
  23. #include <Windows.h>
  24.  
  25.  
  26. // ========================================================================================
  27. // Prototypes for static functions
  28. // ========================================================================================
  29. static OSStatus SetUpMenus ( void );
  30. static OSStatus CreateInputDialog ( void );
  31. static void SetUpDefaultStatus ( void );
  32.  
  33.  
  34. // ========================================================================================
  35. // Initialize
  36. // ========================================================================================
  37. OSStatus Initialize ( void )
  38. {
  39.     OSStatus            err;
  40.     Rect                consoleRect;
  41.     WindowResHandle        windRes;
  42.     
  43.     //------------------------------------------------------------------------------
  44.     // Initialize Toolbox
  45.     //
  46.     InitGraf( (Ptr)&qd.thePort);
  47.     InitFonts();
  48.     FlushEvents( everyEvent, 0);
  49.     InitWindows();
  50.     InitMenus();
  51.     TEInit();
  52.     InitDialogs( nil);
  53.     InitCursor();
  54.  
  55.     gAnalysisMode = 0;
  56.     
  57.     //------------------------------------------------------------------------------
  58.     // Create menu
  59.     //
  60.     err = SetUpMenus();
  61.     nrequire( err, setupMenu_Failure);
  62.     
  63.     //------------------------------------------------------------------------------
  64.     // Create console window
  65.     //
  66.     windRes = (WindowResHandle)Get1Resource( 'WIND', kConsoleWindowResID);
  67.     require( windRes, getConsoleRes_Failure);
  68.     
  69.     HLock( (Handle)windRes);
  70.  
  71.     consoleRect = (**windRes).windRect;
  72.     consoleRect.bottom = qd.screenBits.bounds.bottom - 10;
  73.     err = NewConsoleWindow( &consoleRect, (**windRes).title, (**windRes).visible,
  74.                             (**windRes).procID, (WindowRef)-1L, (**windRes).goAway,
  75.                             (**windRes).refcon, "\pOsaka", 12, &gConsoleWindow);
  76.     
  77.     HUnlock( (Handle)windRes);
  78.     ReleaseResource( (Handle)windRes);
  79.     nrequire( err, createConsole_Failure);
  80.     
  81.     //------------------------------------------------------------------------------
  82.     // Create input window
  83.     //
  84.     err = CreateInputDialog();
  85.     nrequire( err, createDialog_Failure);
  86.     
  87.     SetUpDefaultStatus();
  88.     
  89.     return noErr;
  90.  
  91.     //`````````````````````````````````````````````````````````````````````````````
  92.     // Error handling
  93.     //
  94. createDialog_Failure:
  95.     DisposeConsoleWindow( gConsoleWindow);
  96.     gConsoleWindow = NULL;
  97. createConsole_Failure:
  98. getConsoleRes_Failure:
  99. setupMenu_Failure:
  100.     return err;
  101. }
  102.  
  103.  
  104. // ========================================================================================
  105. // SetUpMenus
  106. // ========================================================================================
  107. static OSStatus SetUpMenus ( void )
  108. {
  109.     OSStatus        err;
  110.     Handle            menuBar;
  111.     MenuRef            fontMenu, sizeMenu, levelMenu;
  112.     
  113.     menuBar = GetNewMBar( kMenuBarResID);
  114.     require_action( menuBar, getMenuBar_Failure, err = ResError(););
  115.     
  116.     SetMenuBar( menuBar);
  117.     
  118.     fontMenu = GetMenu( kFontMenuID);
  119.     InsertMenu( fontMenu, hierMenu);
  120.     
  121.     sizeMenu = GetMenu( kSizeMenuID);
  122.     InsertMenu( sizeMenu, hierMenu);
  123.     
  124.     AppendResMenu( GetMenuHandle( kAppleMenuID), 'DRVR');
  125.     AppendResMenu( GetMenuHandle( kFontMenuID), 'FONT');
  126.     
  127.     levelMenu = GetMenu( kLevelMenuID);
  128.     InsertMenu( levelMenu, hierMenu);
  129.     
  130.     DrawMenuBar();
  131.     
  132.     return noErr;
  133.  
  134.     //`````````````````````````````````````````````````````````````````````````````
  135.     // Error handling
  136.     //
  137. getMenuBar_Failure:
  138.     return err;
  139. }
  140.  
  141.  
  142. // ========================================================================================
  143. // CreateInputDialog
  144. // ========================================================================================
  145. static OSStatus CreateInputDialog ( void )
  146. {
  147.     OSStatus        err;
  148.     DialogRef        dialog;
  149.     InputDialogPtr    infoDialogPtr;
  150.     ControlRef        control;
  151.     
  152.     //------------------------------------------------------------------------------
  153.     // Pre-load env menu because the menu which loaded at creating popup menu
  154.     // is disposed on DisposeDialog. This can be a problem with multi window application.
  155.     //
  156.     {
  157.         MenuRef        envMenu;
  158.         
  159.         envMenu = GetMenu( kEnvironmentMenuID);
  160.         InsertMenu( envMenu, hierMenu);
  161.     }
  162.     
  163.     dialog = GetNewDialog( kInputDialogResID, NULL, (WindowRef)-1L);
  164.     require_action( dialog, getDialog_Failure, err = ResError(););
  165.     
  166.     infoDialogPtr = (InputDialogPtr)NewPtrClear( sizeof( InputDialogRec));
  167.     require_action( infoDialogPtr, allocDialogInfo_Failure, err = memFullErr;);
  168.     
  169.     infoDialogPtr->dialog = dialog;
  170.     infoDialogPtr->analysisBundle.descriptorType = typeNull;
  171.     infoDialogPtr->analysisPath.descriptorType = typeNull;
  172.     
  173.     SetWRefCon( (WindowRef)dialog, (long)infoDialogPtr);
  174.     SetDialogDefaultItem( dialog, kConvertBtnDItemID);
  175.     
  176.     gInputDialog = infoDialogPtr;
  177.  
  178.     //------------------------------------------------------------------------------
  179.     // Create environment menu
  180.     //
  181.     err = SetUpAllAnalysisEnvironment( infoDialogPtr);
  182.     nrequire( err, setupEnvMenu_Failure);
  183.  
  184.     //------------------------------------------------------------------------------
  185.     // Set default environment
  186.     //
  187.     control = (ControlRef)GetDialogItemHandle( dialog, kEnvironPopupDItemID);
  188.     SetControlValue( control, kKanaKanjiMenuItemID);
  189.     
  190.     err = SetAnalysisEnvironment( infoDialogPtr);
  191.     nrequire( err, setDarumaEnv_Failure);
  192.     
  193.     ChangeAnalysisMethod( kBatchAnalysisMode);
  194.  
  195.     ShowWindow( (WindowRef)dialog);
  196.     
  197.     return noErr;
  198.  
  199.     //`````````````````````````````````````````````````````````````````````````````
  200.     // Error handling
  201.     //
  202. setDarumaEnv_Failure:
  203. setupEnvMenu_Failure:
  204.     DisposePtr( (Ptr)infoDialogPtr);
  205. allocDialogInfo_Failure:
  206.     DisposeDialog( dialog);
  207. getDialog_Failure:
  208.     gInputDialog = NULL;
  209.     return err;
  210. }
  211.  
  212.  
  213. // ========================================================================================
  214. // SetUpDefaultStatus
  215. // ========================================================================================
  216. static void SetUpDefaultStatus ( void )
  217. {
  218.     short        menuCount, i;
  219.     Str255        itemName;
  220.     MenuRef        fontMenu, sizeMenu;
  221.     
  222.     //------------------------------------------------------------------------------
  223.     // Set default console font to Osaka-Mono
  224.     //
  225.     fontMenu = GetMenuHandle( kFontMenuID);
  226.     menuCount = CountMItems( fontMenu);
  227.  
  228.     for ( i = 1; i <= menuCount; ++i)
  229.     {
  230.         GetMenuItemText( fontMenu, i, itemName);
  231.         if ( EqualString( itemName, "\pOsakaÅ|ìôïù", false, true))
  232.         {
  233.             CheckItem( fontMenu, i, true);
  234.             SetConcoleWindowFont( gConsoleWindow, "\pOsakaÅ|ìôïù", false);
  235.             break;
  236.         }
  237.     }
  238.     
  239.     //------------------------------------------------------------------------------
  240.     // If Osaka-Mono can't be found, use Osaka
  241.     //
  242.     if ( i > menuCount)
  243.     {
  244.         for ( i = 1; i <= menuCount; ++i)
  245.         {
  246.             GetMenuItemText( fontMenu, i, itemName);
  247.             if ( EqualString( itemName, "\pOsaka", false, true))
  248.             {
  249.                 CheckItem( fontMenu, i, true);
  250.                 SetConcoleWindowFont( gConsoleWindow, "\pOsaka", false);
  251.                 break;
  252.             }
  253.         }
  254.     }
  255.  
  256.     //------------------------------------------------------------------------------
  257.     // Set default console font size to 12
  258.     //
  259.     sizeMenu = GetMenuHandle( kSizeMenuID);
  260.     menuCount = CountMItems( sizeMenu);
  261.     
  262.     for ( i = 1; i <= menuCount; ++i)
  263.     {
  264.         GetMenuItemText( sizeMenu, i, itemName);
  265.         if ( EqualString( itemName, "\p12", false, true))
  266.         {
  267.             CheckItem( sizeMenu, i, true);
  268.             break;
  269.         }
  270.     }
  271. }
  272.  
  273.  
  274.  
  275.